package com.sxdz.web.goods

import com.sxdz.constant.MessageConstant
import com.sxdz.controller.service.goods.IGoodsBannerService
import com.sxdz.controller.service.goods.IGoodsService
import com.sxdz.models.TGoodsBanner
import com.sxdz.models.TGoodsInfo
import com.sxdz.models.common.JsonResult
import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.RestController
/**
 * Created by LiYan on 2016/8/4.
 * 互动点歌
 */
@RestController
@CompileStatic
@TypeChecked
@RequestMapping("music")
class MusicAction {
    Logger logger = LoggerFactory.getLogger(this.getClass())

    @Autowired
    private IGoodsService goodsService;
    @Autowired
    private IGoodsBannerService goodsBannerService

    @RequestMapping(value = "getMusic", method = RequestMethod.GET)
    @ResponseBody
    getMusic(){
        def param=[:]
        param<<[goodsModule:'music']
        List<TGoodsInfo> list=new ArrayList<TGoodsInfo>()
        list=goodsService.findListByParams(param)
        if(list==null||list.size()==0){
            logger.info("未查询到商品信息")
            return new JsonResult<Object>(MessageConstant.FAIL_QUERY,null)
        }else{
            logger.info("查询到商品信息")
            return new JsonResult<Object>(MessageConstant.SUCCESS,list)
        }
    }

    /**
     * 查询musicBanner信息
     * @param goodsId
     * @return
     */
    @RequestMapping(value = "getMusicBan/{goodsId}", method = RequestMethod.GET)
    @ResponseBody
    getMusicBanner(@PathVariable("goodsId") Long goodsId){
        def map=[:]
        map<<[goodsId:goodsId]
        TGoodsBanner tGoodsBanner=goodsBannerService.findObj(map) as TGoodsBanner
        return new JsonResult<Object>(MessageConstant.SUCCESS,tGoodsBanner)
    }

}
